using B.S.Data.MES.API.Applications.BaseData.Command.MaterialGroupCommand;
using B.S.Domain.BasicData.MaterialManagement.MaterialGroups;
using B.S.Domain.BasicData.MaterialManagement.Material_type;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using B.S.Domain.Dto.WuLiaoDto;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.MaterialGroupCommandHandlers
{
    public class GetAllMaterialGroupsCommandHandler : IRequestHandler<GetAllMaterialGroupsCommand, APIRequst<List<Material_group>>>
    {
        private readonly IBaseRepository<Material_group> _materialGroupRepository;

        public GetAllMaterialGroupsCommandHandler(
            IBaseRepository<Material_group> materialGroupRepository)
        {
            _materialGroupRepository = materialGroupRepository;
        }

        public Task<APIRequst<List<Material_group>>> Handle(GetAllMaterialGroupsCommand request, CancellationToken cancellationToken)
        {
            // 获取所有未删除的物料群组，并关联物料类型表
            var list = _materialGroupRepository.GetAll();
            return Task.FromResult(new APIRequst<List<Material_group>>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString(),
                Data = list.ToList()
            });
        }
    }
}